package com.fellowera.controller;
 

import org.jboss.seam.solder.logging.Category;
 
 

import javax.annotation.PostConstruct;
import javax.enterprise.event.Event;
import javax.enterprise.inject.Model;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;
 
import org.jboss.logging.Logger;

import com.fellowera.bean.WewaBean;
import com.fellowera.model.Wewa;

// Adding the @Stateful annotation eliminates need for manual transaction demarcation
// @javax.ejb.Stateful
// The @Model stereotype is a convenience mechanism to make this a request-scoped bean that has an EL name
// Read more about the @Model stereotype in this FAQ: http://sfwk.org/Documentation/WhatIsThePurposeOfTheModelAnnotation
@Model
public class CreateNewWewa {
   
	@Inject
	WewaBean wewaBean;

	@Inject
    @Category("fellowera")
    private Logger log;

   @Inject
    private Event<WewaBean> wewaBeanEventSrc;

    private Wewa newWewa;

    @Produces
    @Named
    public Wewa getNewWewa() {
        return newWewa;
    }

    public void register() throws Exception {
        log.info("Registering " + newWewa.getName());
        // UserTransaction only needed when bean is not an EJB
     
        wewaBean.setInstance(newWewa);
        wewaBean.save();
      
        wewaBeanEventSrc.fire(wewaBean);
        initNewWewa();
    }

    @PostConstruct
    public void initNewWewa() {
        newWewa = new Wewa();
    }
}
